from dataclasses import dataclass
from pathlib import Path


class CompilerCmd:
    DEV_NULL = Path('/dev/null')

    def __init__(self, build_dir: Path) -> None:
        self.build_dir = build_dir

    @property
    def es2panda(self) -> Path:
        return self.build_dir / 'bin' / 'es2panda'

    def __call__(self, ets_file: Path, output: Path = DEV_NULL, *, gen_stdlib: bool = False) -> list[str]:
        return [
            f'{self.es2panda!s}',
            f'--arktsconfig={self.build_dir!s}/tools/es2panda/generated/arktsconfig.json',
            f'--gen-stdlib={str(gen_stdlib).lower()}',
            '--extension=ets',
            '--opt-level=0',
            f'--output={output!s}',
            f'{ets_file!s}',
        ]


@dataclass
class Config:
    build_dir: Path


def compiler_cmd(config: Config) -> CompilerCmd:
    return CompilerCmd(config.build_dir)
